package com.yoo.ons.dialog

import android.app.Activity
import android.content.Context
import android.graphics.Point
import android.graphics.Rect
import android.os.Handler
import android.view.Display
import android.view.View
import android.view.animation.AnimationUtils
import android.widget.EditText
import android.widget.GridLayout
import android.widget.ImageView
import android.widget.TextView
import androidx.constraintlayout.widget.ConstraintLayout
import androidx.fragment.app.FragmentActivity
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.yoo.module_base.utils.setSystemBottomNavBarColor
import com.yoo.module_base.utils.setSystemBottomNavBarNoColor
import com.yoo.ons.R
import com.yoo.ons.adapter.UserTOAdapter
import com.yoo.ons.base.adpater.AdapterCallback
import com.yoo.ons.model.TurnOnsListModel
import razerdp.basepopup.BasePopupWindow

class UpdateTOPopup(activity: Activity, var toList:ArrayList<TurnOnsListModel>, var callBack:(toList:ArrayList<TurnOnsListModel>)->Unit):BasePopupWindow(activity) {
    init {
        setContentView(R.layout.popup_update_to)
        initView(activity)
        showAnimation=  AnimationUtils.loadAnimation(activity, com.yoo.module_res.R.anim.anims_slide_in_bottom)
        dismissAnimation=  AnimationUtils.loadAnimation(activity, com.yoo.module_res.R.anim.anims_slide_out_bottom)
    }

    fun initView(activity:Activity){
        val popupClose = findViewById<ImageView>(R.id.popup_close)
        val popupTOList = findViewById<RecyclerView>(R.id.popup_t_o_list)
        val popupUpdateTOSave = findViewById<TextView>(R.id.popup_update_to_save)
        popupTOList.layoutManager=GridLayoutManager(activity,2)
        val userTOAdapter = UserTOAdapter(true)
        popupTOList.adapter= userTOAdapter
        popupClose.setOnClickListener {
            dismiss()
        }

        popupUpdateTOSave.setOnClickListener {
            callBack.invoke(toList)
            dismiss()
        }



        //设置底部导航栏颜色
        setSystemBottomNavBarColor(activity)
        onDismissListener =object : OnDismissListener() {
            override fun onDismiss() {
                setSystemBottomNavBarNoColor(activity)
            }

        }
    }
}